package cn.factorybox.item.controller;

import cn.factorybox.common.entity.Result;
import cn.factorybox.item.annotation.ControllerLogAnnotation;
import cn.factorybox.item.service.PersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-05-30 18:32
 */

@Api(tags = "人员管理")
@RestController
public class PersonController {

    @Autowired
    private PersonService personService;

    @ControllerLogAnnotation(moduleName = "人员管理", functionName = "获取人员列表")
    @ApiOperation(value = "获取人员列表", notes = "获取人员列表")
    @GetMapping("person")
    public Result selectPersonList(@RequestParam("deviceID") String deviceID) {
        Map<String,Object> map = personService.selectListByDeviceID(deviceID);
        return Result.ok(map,"成功获取设备列表数据");
    }

    @ControllerLogAnnotation(moduleName = "人员管理", functionName = "新增人员")
    @ApiOperation(value = "新增人员", notes = "新增人员")
    @PostMapping("person")
    public Result addPerson(@RequestBody Map<String,Object> map) {
        personService.insert(map);
        return Result.ok("新建人员成功");
    }

    @ControllerLogAnnotation(moduleName = "人员管理", functionName = "修改人员信息")
    @ApiOperation(value = "修改人员信息", notes = "修改人员信息")
    @PutMapping("person")
    public Result updatePerson(@RequestBody Map<String,Object> map) {
        personService.update(map);
        return Result.ok("修改人员信息成功");
    }

    @ControllerLogAnnotation(moduleName = "人员管理", functionName = "通过id获取人员信息")
    @ApiOperation(value = "通过id获取人员信息", notes = "通过id获取人员信息")
    @GetMapping("personById")
    public Result selectPersonListById(@RequestParam("id") String id) {
        Map<String,Object> map = personService.selectListById(id);
        return Result.ok(map,"成功获取设备列表数据");
    }
}
